<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<%@ include file="/include/header.jsp"%>
<title>${basePageTitle}</title>
<link href="${baseURL}/css/um/register.css" rel="stylesheet" type="text/css" />
<link href="${baseURL}/css/um/default.css" rel="stylesheet" type="text/css" />

<link type="text/css" rel="stylesheet" href="${baseURL}/jsFile/formvalidator/style/validator.css"></link>
<script src="${baseURL}/jsFile/formvalidator/formValidator-4.0.1.js" type="text/javascript"></script>
<script src="${baseURL}/jsFile/formvalidator/formValidatorRegex.js" type="text/javascript"></script>
<script src="${baseURL}/js/layer/layer.min.js?v=1.8.0" type="text/javascript"></script>

<style type="text/css">
.css_btn_class {
	font-size:11px;
	font-family:Arial;
	font-weight:normal;
	-moz-border-radius:5px;
	-webkit-border-radius:5px;
	border-radius:5px;
	border:1px solid #120f12;
	padding:6px 28px;
	text-decoration:none;
	background:-moz-linear-gradient( center top, #ffffff 5%, #e0d9e0 100% );
	background:-ms-linear-gradient( top, #ffffff 5%, #e0d9e0 100% );
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#e0d9e0');
	background:-webkit-gradient( linear, left top, left bottom, color-stop(5%, #ffffff), color-stop(100%, #e0d9e0) );
	background-color:#ffffff;
	color:#141114;
	display:inline-block;
	text-shadow:1px 1px 0px #faf2fa;
 	-webkit-box-shadow:inset 1px 1px 0px 0px #d0b0d;
 	-moz-box-shadow:inset 1px 1px 0px 0px #d0b0d;
 	box-shadow:inset 1px 1px 0px 0px #d0b0d;
}.css_btn_class:hover {
	background:-moz-linear-gradient( center top, #e0d9e0 5%, #ffffff 100% );
	background:-ms-linear-gradient( top, #e0d9e0 5%, #ffffff 100% );
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#e0d9e0', endColorstr='#ffffff');
	background:-webkit-gradient( linear, left top, left bottom, color-stop(5%, #e0d9e0), color-stop(100%, #ffffff) );
	background-color:#e0d9e0;
}.css_btn_class:active {
	position:relative;
	top:1px;
}
</style>
<script type="text/javascript">
head = document.getElementsByTagName("head")[0];
cssLink = document.createElement("link");
cssLink.rel = cssLink.rev = "stylesheet";
cssLink.type = "text/css";
cssLink.media = "screen";
head.appendChild(cssLink);
if ($.browser.msie) {
	(function() {
		var e = "article,aside,details,figure,footer,header,nav,section"
				.split(','), i = e.length;
		while (i--) {
			document.createElement(e[i]);
		}
	})();
	cssLink.href = "${baseURL}/css/download_ie.css";
} else {
	cssLink.href = "${baseURL}/css/download.css";
}
$(document).ready(function() {
	
	var isFail = document.getElementById("register.Rfail").value;
	var isSuccess=document.getElementById("register.Rsuccess").value;
	var isHasEmai = document.getElementById("register.ishasEmai").value;
	var isHasName=document.getElementById("register.ishasName").value;
	var invitatioCodeFail = document.getElementById("register.invitatioCodeFail").value;

	var code='${param.code}';
	
	if(code && code.length>0){
		var hbaseKey =  code.substring(0,5);
		$("#invitation_code").val(code);
		$("#select_dpmt option[value='"+hbaseKey+"']").attr("selected", true);
		$("#select_dpmt").attr("disabled", true);
		$("#invitation_code").attr("disabled", true);
	}
	//表单验证
	validator();
	//提交注册
	$("#btnSubmit").click(function(){
		 var code=document.getElementById("invitation_code").value;
		 var hbaseKey=document.getElementById("select_dpmt").value;
		if($.formValidator.pageIsValid()){//验证是否通过
			$.ajax({ 
				type: "post", 
				async: false,//同步
				url: "${baseURL}/register/register.action?codes="+encodeURI(encodeURI(code))+"&hbaseKey="+encodeURI(encodeURI(hbaseKey)), 
				data : $("#form1").serialize(),
				dataType: "json",
				success: function (result) { 
					if(result && result.hasOk){//成功，则跳转至关注航线页面
						$("#j_username").val(result.bean.userName);
						$("#j_password").val(result.bean.password);
						$("#loginForm").submit();//登陆
					}else{
						$(this).attr("disabled", false);
						alert(result.message);
					}
				}
			});
		}
	});
});

/**
 * 表单验证
 */
 function validator(){
 	$.formValidator.initConfig({
 		formID:"form1",
 		debug:false,
 		submitOnce:true,
		submitAfterAjaxPrompt : document.getElementById("register.validated").value
	});
	$("#email").formValidator({onShow:document.getElementById("register.inputEmail").value,onFocus:document.getElementById("register.emailCheck").value,
		onCorrect:document.getElementById("register.enterRight").value}).inputValidator({min:6,max:50,onError:document.getElementById("register.lenghtEr").value})
	.regexValidator({regExp:"^([a-z0-9A-Z]+[-|\\.]?)+([-_][a-z0-9A-Z]+)*@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$",onError:document.getElementById("register.emailFormatEr").value});
	
	$("#user_name").formValidator({onShow:document.getElementById("register.inputUserName").value,onFocus:document.getElementById("register.userLenght").value,
		onCorrect:document.getElementById("register.enterRight").value})
	.regexValidator({regExp:"username",dataType:"enum",onError:document.getElementById("register.formatEr").value})
	.inputValidator({min:3,max:20,onError:document.getElementById("register.illegalityName").value}).ajaxValidator({
		type: "get", 
		url: "${baseURL}/register/checkUserName.action",
		dataType:'json',
		success: function (result) { 
			return !result.hasOk;
		},
		onError: document.getElementById("register.userExists").value,
		onWait : document.getElementById("register.checkUser").value
	});
	
	$("#user_password").formValidator({onShow:document.getElementById("register.inputPass").value,onFocus:document.getElementById("register.lessChar").value,onCorrect:document.getElementById("register.enterRight").value})
	.regexValidator({regExp:"^([a-zA-z0-9]*[a-zA-z]+[a-zA-z0-9]*)+$",onError:document.getElementById("register.passFormate").value})
	.inputValidator({min:6,max:12,empty:{leftEmpty:false,rightEmpty:false,emptyError:document.getElementById("register.nullSign").value},onError:document.getElementById("register.inputConfirmPass").value});
	
	$("#user_password_confirmation").formValidator({onShow:document.getElementById("register.inputConfirmPass").value,onFocus:document.getElementById("register.lessChar").value,
		onCorrect:document.getElementById("register.enterRight").value})
	.inputValidator({min:6,max:12,empty:{leftEmpty:false,rightEmpty:false,emptyError:document.getElementById("register.nullSign").value},onError:document.getElementById("register.illegalityName").value})
	.compareValidator({desID:"user_password",operateor:"=",onError:document.getElementById("register.passCorrect").value});

	
	$("#user_phone").formValidator({empty:true,onShow:document.getElementById("register.inputPhone").value,onFocus:document.getElementById("register.phoneFormate").value,onCorrect:document.getElementById("register.thanks").value})
	.regexValidator({regExp:["tel","mobile"],dataType:"enum",onError:document.getElementById("register.formatEr").value});
	
	$("#user_qq").formValidator({empty:true,onShow:document.getElementById("register.inputQQ").value,onFocus:document.getElementById("register.qqFormate").value,onCorrect:document.getElementById("register.thanks").value})
	.inputValidator({min:5,max:10,onError:document.getElementById("register.qqLengthForm").value})
	.regexValidator({regExp:"qq",dataType:"enum",onError:document.getElementById("register.formatEr").value});
	
	
	$("#agree").formValidator({tipID:"agreeTip",onShow:document.getElementById("register.readCarefully").value,onFocus:document.getElementById("register.agreeAndChoise").value,onCorrect:document.getElementById("register.thanks").value})
	.inputValidator({min:1,onError:document.getElementById("register.sureForChoise").value});
	
	$("#select_dpmt").formValidator({onShow:document.getElementById("register.inputCompany").value,onCorrect:document.getElementById("register.thanks").value})
	.inputValidator({min:1,onError:document.getElementById("register.choiseCompanyName").value});
	
	$("#select_group").formValidator({onShow:document.getElementById("register.inputUserGroup").value,onCorrect:document.getElementById("register.thanks").value})
	.inputValidator({min:1,onError:document.getElementById("register.choiseUGroup").value});
	
	$("#invitation_code").formValidator({onShow:document.getElementById("register.inputInvitationCode").value,onCorrect:document.getElementById("register.thanks").value})
	.inputValidator({min:1,onError:document.getElementById("register.choiseInvitationCode").value}); 
	
}
//发送页面跳转
function getCode(){
	var url="${baseURL}/register/sendcoderequest/view.action";
	$.layer({
	    type : 2,
	    title : '<s:text name="register.getRegisterCode"/>',
	    iframe : {src : url},
	    area : ['710px' , '360px'],
	    offset : ['100px','']
	});
}



 </script>
</head>
<body id="aboutus">
	<header>
		<%@ include file="/include/start/start_header1.jsp" %>
	</header>
 	<div id="center">
 	  	<form action="${baseURL}/j_spring_security_check" id="loginForm" name="loginForm" method="post">
 		<input type="hidden"  id="j_username" name="j_username" value=""/>
 		<input type="hidden"  id="j_password" name="j_password" value=""/>
 	</form>
 	<form action="" id="userFrom" name="userFrom" method="post">
 		<!-- 国际化信息		 -->
 		<input type="hidden" id="register.validated" value="<s:text name="register.validated"/>" /> 
 		<input type="hidden" id="register.checkUser" value="<s:text name="register.checkUser"/>" />  
 		<input type="hidden" id="register.userExists" value="<s:text name="register.userExists"/>" />  
 		<input type="hidden" id="register.inputEmail" value="<s:text name="register.inputEmail"/>" />
 		<input type="hidden" id="register.inputUserName" value="<s:text name="register.inputUserName"/>" />  
 		<input type="hidden" id="register.inputPass" value="<s:text name="register.inputPass"/>" />  
 		<input type="hidden" id="register.inputConfirmPass" value="<s:text name="register.inputConfirmPass"/>" />  
 		<input type="hidden" id="register.inputCompany" value="<s:text name="register.inputCompany"/>" />  
 		<input type="hidden" id="register.inputPhone" value="<s:text name="register.inputPhone"/>" />  
 		<input type="hidden" id="register.inputQQ" value="<s:text name="register.inputQQ"/>" />  
 		<input type="hidden" id="register.inputUserGroup" value="<s:text name="register.inputUserGroup"/>" />  
 		<input type="hidden" id="register.inputInvitationCode" value="<s:text name="register.inputInvitationCode"/>" />  
 		<input type="hidden" id="register.thanks" value="<s:text name="register.thanks"/>" />  
 		<input type="hidden" id="register.readCarefully" value="<s:text name="register.readCarefully"/>" />
 		<input type="hidden" id="register.emailFormatEr" value="<s:text name="register.emailFormatEr"/>" />
 		<input type="hidden" id="register.formatEr" value="<s:text name="register.formatEr"/>" />
 		<input type="hidden" id="register.lenghtEr" value="<s:text name="register.lenghtEr"/>" />
 		<input type="hidden" id="register.illegalityName" value="<s:text name="register.illegalityName"/>" />
 		<input type="hidden" id="register.lessChar" value="<s:text name="register.lessChar"/>" />
 		<input type="hidden" id="register.userLenght" value="<s:text name="register.userLenght"/>" />
 		<input type="hidden" id="register.nullSign" value="<s:text name="register.nullSign"/>" />
 		<input type="hidden" id="register.passFormate" value="<s:text name="register.passFormate"/>" />
 		<input type="hidden" id="register.passCorrect" value="<s:text name="register.passCorrect"/>" />
 		<input type="hidden" id="register.choiseCompanyName" value="<s:text name="register.choiseCompanyName"/>" />
 		<input type="hidden" id="register.phoneFormate" value="<s:text name="register.phoneFormate"/>" />
 		<input type="hidden" id="register.qqFormate" value="<s:text name="register.qqFormate"/>" />
 		<input type="hidden" id="register.qqLengthForm" value="<s:text name="register.qqLengthForm"/>" />
 		<input type="hidden" id="register.choiseUGroup" value="<s:text name="register.choiseUGroup"/>" />
 		<input type="hidden" id="register.choiseInvitationCode" value="<s:text name="register.choiseInvitationCode"/>" />
 		<input type="hidden" id="register.agreeAndChoise" value="<s:text name="register.agreeAndChoise"/>" />
 		<input type="hidden" id="register.sureForChoise" value="<s:text name="register.sureForChoise"/>" />
 		<input type="hidden" id="register.enterRight" value="<s:text name="register.enterRight"/>" />
 		<input type="hidden" id="register.emailCheck" value="<s:text name="register.emailCheck"/>" />
 		<input type="hidden" id="register.Rfail" value="<s:text name="register.Rfail"/>" />
 		<input type="hidden" id="register.Rsuccess" value="<s:text name="register.Rsuccess"/>" />
 		<input type="hidden" id="register.ishasEmai" value="<s:text name="register.ishasEmai"/>" />
 		<input type="hidden" id="register.ishasName" value="<s:text name="register.ishasName"/>" />
 		<input type="hidden" id="register.invitatioCodeFail" value="<s:text name="register.invitatioCodeFail"/>" />
 		<input type="hidden" id="register.getRegisterCode" value="<s:text name="register.getRegisterCode"/>"/>
 		
 	</form>
		<div class="register_content">
			<div class="register_content_top"></div>
			<div class="register_content_center" style="min-height: 500px;">
				<div class="second_title" style="font-weight: bold;"><s:i18n name="register"> 
  							<s:text name="register.register"></s:text>
					</s:i18n></div>
				<form action="" id="form1" name="form1" method="post" >
					<table align="center" border="0" cellpadding="0" cellspacing="0"
						width="100%">
						<tbody>
							<tr>
								<td></td>
								<td colspan="2">
									<h3 class="login_error"></h3>
								</td>
							</tr>
							<tr>
								<td align="right" valign="middle" width="80">Email<span
									class="req">*</span>&nbsp;
								</td>
								<td><input class="input_205 input_txt" id="email"
									value="${registerVo.email }" name="registerVo.email" size="30"
									type="text" /></td>
								<td align="left"><div id="emailTip" style="width: 270px"></div></td>
							</tr>
							<tr>
								<td align="right" valign="middle"><s:i18n name="register"> <s:text name="register.username"></s:text></s:i18n><span class="req">*</span>&nbsp;
								</td>
								<td><input class="input_205 input_txt cname" id="user_name"
									value="${registerVo.userName}" maxlength="20" minlength="3"
									name="registerVo.userName" size="20" type="text" /></td>
								<td align="left"><div id="user_nameTip" style="width: 270px"></div></td>
							</tr>
							<tr>
								<td align="right" valign="middle"><s:i18n name="register"> <s:text name="register.password"></s:text></s:i18n><span class="req">*</span>&nbsp;
								</td>
								<td><input class="input_205 input_txt" id="user_password"
									maxlength="12" minlength="6" value="${registerVo.password }"
									name="registerVo.password" size="12" type="password"></td>
								<td align="left"><div id="user_passwordTip" style="width: 270px"></div></td>
							</tr>
							<tr>
								<td align="right" valign="middle"><s:i18n name="register"> <s:text name="register.confirmPassword"></s:text></s:i18n><span class="req">*</span>&nbsp;
								</td>
								<td><input class="input_205 input_txt"
									id="user_password_confirmation" maxlength="16" minlength="6"
									value="${registerVo.cfpassword }" name="registerVo.cfpassword"
									size="16" type="password"></td>
								<td align="left"><div id="user_password_confirmationTip"
										style="width: 270px"></div></td>
							</tr>
							<tr id="select_companys" class="">
								<td align="right" valign="middle"><s:i18n name="register"> 
								<s:text name="register.company"></s:text></s:i18n><span class="req">*</span>&nbsp;
								</td>
								<td><select name="registerVo.sourceId" id="select_dpmt" class="input_txt">
										<option value=" "><s:i18n name="register"> <s:text name="register.select"></s:text></s:i18n></option>
										<c:forEach var="bean" items="${sourceList}" varStatus="stat">
											<option value="${bean.hbaseKey}">${bean.name}</option>
										</c:forEach>
								</select></td>
								<td align="left"><div id="select_dpmtTip" style="width: 270px"></div></td>
							</tr>
							<tr>
								<td align="right" valign="middle"><s:i18n name="register"> <s:text name="register.telephoneNumber"></s:text></s:i18n>&nbsp;</td>
								<td><input class="input_205 input_txt" id="user_phone"
									value="${registerVo.phone }" name="registerVo.phone" size="30"
									type="text"></td>
								<td align="left"><div id="user_phoneTip" style="width: 270px"></div></td>
							</tr>
							<tr>
								<td align="right" valign="middle">QQ&nbsp;</td>
								<td><input class="input_205 input_txt" maxlength="10"
									minlength="5" id="user_qq" value="${registerVo.qq }"
									name="registerVo.qq" size="30" type="text" /></td>
								<td align="left"><div id="user_qqTip" style="width: 270px"></div></td>
							</tr>
							<tr>
								<td align="right" valign="middle"><s:i18n name="register"> <s:text name="register.userGroups"></s:text></s:i18n><span class="req">*</span>&nbsp;
								</td>

								<td><select name="registerVo.group" id="select_group" class="input_txt">
										<option value=" "><s:i18n name="register"> <s:text name="register.select"></s:text></s:i18n></option>
										<c:forEach var="bean" items="${roleList}" varStatus="stat">
											<option value="${bean.id}">${bean.name}</option>
										</c:forEach>
								</select></td>
								<td align="left"><div id="select_groupTip" style="width: 270px"></div></td>
							</tr>
							<tr>
								<td align="right" valign="middle">
								<s:i18n name="register"> <s:text name="register.invitationCode"></s:text></s:i18n>
								<span class="req">*</span>&nbsp;
								</td>
								<td><input class="input_205 input_txt" id="invitation_code"
									value="" maxlength="50" minlength="2"
									name="registerVo.invitationCode" size="20" type="text"/>
								</td>
								
								<td align="left"><div id="invitation_codeTip" style="width: 270px"></div>
								</td> 
							</tr>
                   <tr class="agree">
                         <td colspan="2">
                             &nbsp;&nbsp;<input name="agree" id="agree" class="checkbox"  type="checkbox">
                             <span><s:i18n name="register"> <s:text name="register.agree"></s:text></s:i18n>
                             <a href="${baseURL}/system/start/termsService.action" target="_blank">
                             <s:i18n name="register"> <s:text name="register.service"></s:text></s:i18n></a>
                             <s:i18n name="register"> <s:text name="register.and"></s:text></s:i18n>
                             <a href="${baseURL}/system/start/legalNotice.action" target="_blank">
                             <s:i18n name="register"> <s:text name="register.law"></s:text></s:i18n></a>
                             </span><p></p>
                         </td>
                         <td align="left"><div id="agreeTip" style="width:270px"></div></td>
                     </tr>
                     <tr class="act">
                         <td colspan="2">
                            <input class="new_button_submit" id="btnSubmit" value="<s:text name="register.register"/>" type="button" />
                         </td>  
                         <td align="left"><s:i18n name="register"> <s:text name="register.noRegisterCode"></s:text>
                         </s:i18n><a href="javascript:getCode();" class="login">
          				  <s:i18n name="register"> <s:text name="register.getRegisterCode"></s:text></s:i18n></a><br/>
		                        <s:i18n name="register"> <s:text name="register.finishRegister"></s:text></s:i18n>
                                <a href="${baseURL}/system/start/logon.action" class="login"><s:i18n name="register"> <s:text name="register.signin"></s:text></s:i18n></a></td>
                     </tr>
                 </tbody></table>
				</form>       
			</div>
			<div class="register_content_bottom"></div>
		</div>
	</div>

	<footer>
		<%@ include file="/include/home/home_footer.jsp" %> 
	</footer>
</body>
</html>